package kisti.daniel.main;


import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import kisti.module.server.ConnectToGridServer;
import kisti.module.log.*;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;



/**
 * <pre>
 * kisti.daniel.main
 *   |_ getInfo.java
 *
 * </pre>
 *
 * Desc :
 * @Company : KISTI
 * @Author :daniel
 * @Date   :2012. 1. 27. 오후 5:42:07
 * @Version:
 *
 */
public class getInfo {

	
	ConnectToGridServer connectToGridServer = new ConnectToGridServer();
	
	
	
	
	public getInfo() {
		// TODO Auto-generated constructor stub
					
		
	}

	

	
	
	
	/**
	 * 
	 * Desc :
	 * @Method Name : get
	 *
	 */
	public void get() {
		
//		
//		String result = (String) connectToGridServer.requestDataToServer("samInfo");
//
//		// 파싱
//		try {
//			DocumentBuilderFactory factory = DocumentBuilderFactory
//					.newInstance();
//			DocumentBuilder builder = factory.newDocumentBuilder();
//			InputStream istream = new ByteArrayInputStream(result.getBytes("utf-8"));
//			Document doc = builder.parse(istream);
//
////			Log.debug("[Sam_Helper]", "[loadSamInfoData] : ", result);
//
//			Element order = doc.getDocumentElement();
//			NodeList items = order.getElementsByTagName("Node");
//			Element element = (Element) items.item(0);
//
//			cpuUse = Double.parseDouble(getChildren(element, "cpuUse"));
//
//			memTotal = Double.parseDouble(getChildren(element, "memTotal"));
//			memUse = Double.parseDouble(getChildren(element, "memUse"));
//			memUsage = (memUse / memTotal) * 100;
//
//			diskIn = Double.parseDouble(getChildren(element, "diskRead"));
//			diskOut = Double.parseDouble(getChildren(element, "diskWrite"));
//			netIn = Double.parseDouble(getChildren(element, "netIn"));
//			netOut = Double.parseDouble(getChildren(element, "netOut"));
//
//		} catch (Exception e) {
//			// TODO: handle exception
//			e.printStackTrace();
//		}

	}

	/**
	 * 
	 * Desc : XML 데이터 파싱 / 해당 속성값 반환
	 * 
	 * @Method Name : getChildren
	 * @param element
	 * @param tagName
	 * @return tag에 의한 속성값 찾아서 반환
	 * 
	 */
	private static String getChildren(Element element, String tagName) {
		NodeList list = element.getElementsByTagName(tagName);
		Element cElement = (Element) list.item(0);

		if (cElement.getFirstChild() != null) {
			return cElement.getFirstChild().getNodeValue();
		} else {
			return "";
		}
	}

}
